<?php defined('SYS_PATH') or die('No direct script access.');
/**
 * Response class
 *
 * @author zendzhang<zendzhang@hotmail.com>
 * @version $Id: Response.php 9 2013-01-14 03:24:50Z zendzhang@hotmail.com $
 */
class TrueBlood_Response extends TrueBlood
{
    /**
     * Set Cookie
     *
     * @param string $name
     * @param string $value
     * @param int $expire
     */
    public static function cookie($name, $value = null, $expire = null)
    {
        self::$load->cookie->set($name, $value, $expire);
    }

    /**
     * Set response charset
     *
     * @param string $enc
     * @param string $type
     * @return void
     */
    public static function charset($encode = 'UTF-8', $type = 'text/html')
    {
        header("Content-Type:$type;charset=$encode");
    }

    /**
     * Redirect to other url
     *
     * @param string $url
     * @param int $time
     * @param int $code
     * @return void
     */
    public static function redirect($url, $time = 0, $code = 302)
    {
        $url = str_replace(array("\n", "\r"), '', $url);
        if (!headers_sent())
        {
            if (0 === $time)
            {
                header("Location: " . $url, true, $code);
            }
            else
            {
                header("Refresh:{$time};url={$url}");
            }
            exit();
        }
        else
        {
            $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
            die($str);
        }
    }

    /**
     * Forces the user's browser not to cache the results of the current request.
     *
     * @return void
     */
    public static function disableBrowserCache()
    {
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
    }
}

?>